{
  "properties" : { },
  "id" : "6d99e5a020eb47fd80ffa099b992b969",
  "script" : null,
  "groupId" : "ded0996d4aa14841ae2d40edb1fa6d63",
  "name" : "修改设备信息",
  "createTime" : 1727071122993,
  "updateTime" : 1726305285203,
  "lock" : "1",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "updateDevice",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n    \"snCode\": \"\",\r\n    \"deviceName\": \"阜康抽蓄电站\",\r\n    \"ip\": \"60.2.7.42\",\r\n    \"dccId\": \"\",\r\n    \"operateDate\": \"2024-09-10 15:31:01.855\",\r\n    \"deviceUsername\": \"2133321\",\r\n    \"devicePassword\": \"333\",\r\n    \"protype\": \"1\",\r\n    \"devicePort\": \"22\",\r\n    \"snmpVersion\": \"1\",\r\n    \"communityR\": \"SGD!@#$-XB_123\",\r\n    \"communityRW\": \"SGD!@#$-XB_123\",\r\n    \"portRW\": \"161\",\r\n    \"deviceModelId\": \"\",\r\n    \"stationProp\": 4,\r\n    \"stationType\": 6,\r\n    \"deviceType\": 1,\r\n    \"openStatus\": 1,\r\n    \"deviceFirm\": \"\",\r\n    \"voltageLevel\": 3,\r\n    \"accessNetwork\": 1,\r\n    \"netRegion\": 1,\r\n    \"name\": \"\",\r\n    \"pingThreshold\": \"\",\r\n    \"id\": \"D6263831650352036929\",\r\n    \"deviceAlias\": \"\",\r\n    \"assetNo\": \"\",\r\n    \"expiryDate\": \"\",\r\n    \"softVersion\": \"\",\r\n    \"location\": \"\",\r\n    \"stationName\": \"\",\r\n    \"dccCaliber\": \"\",\r\n    \"createTime\": \"\",\r\n    \"updateTime\": \"\",\r\n    \"mtncStatus\": 0,\r\n    \"groupName\": \"新疆\",\r\n    \"deviceId\": \"D6263831650352036929\",\r\n    \"rocommunity\": \"SGD!@#$-XB_123\",\r\n    \"rwcommunity\": \"SGD!@#$-XB_123\",\r\n    \"portRw\": 161,\r\n    \"portTrap\": 162,\r\n    \"useagent\": \"\",\r\n    \"agentserver\": \"\",\r\n    \"managestatus\": \"\",\r\n    \"retryCount\": \"\",\r\n    \"timeout\": \"\",\r\n    \"securityName\": \"\",\r\n    \"securityLevel\": \"\",\r\n    \"authProtocol\": \"\",\r\n    \"authPassword\": \"\",\r\n    \"privProtocol\": \"\",\r\n    \"privPassword\": \"\",\r\n    \"proType\": \"\",\r\n    \"sftpEnable\": \"\",\r\n    \"cfgCron\": \"\",\r\n    \"oldIp\": \"60.2.7.42\"\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 500,\n    \"success\": false,\n    \"data\": {},\n    \"msg\": \"系统维护中，请稍后重试。\"\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "status",
      "value" : "500",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "系统内部出现错误",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import org.springblade.core.tool.utils.StringUtil
import org.apache.commons.lang3.StringUtils
import org.springblade.core.tool.api.R
import com.kd.ndmp.util.IdUtil

if (StringUtil.isEmpty(body.ip)) {
    return R.fail("IP地址不能为空。");
}

var deviceId = IdUtil.generateDeviceId(body.ip)

if (StringUtil.isEmpty(body.stationType)) {
    body.stationType = 6; //厂站类型
}

db.table('ndmp_device').primary('id').update({
    id: deviceId,
    snCode: body.snCode, //sncode
    dccId: body.dccId, //调度机构
    deviceName: body.deviceName, //设备名称
    groupId: body.groupId, //站点属性地网省网
    stationProp: body.stationProp, //所属场站
    stationType: body.stationType, //所属场站
    deviceModelId: body.deviceModelId, //设备型号
    voltageLevel: body.voltageLevel, //电压类型
    operateDate: body.operateDate, //投运时间
    deviceType: body.deviceType, //设备类型
    openStatus: body.openStatus, //开通状况
    netRegion: body.netRegion, //网络区域
    accessNetwork: body.accessNetwork //接入网段
})


var netSnmpProtocol = db.table('ndmp_net_snmp_protocol').where().eq("device_id", deviceId).selectOne()

var snmpId = IdUtil.getSnowflakeNextId()
if (netSnmpProtocol != null) {
    db.update("""
    update ndmp_net_snmp_protocol set snmp_version = #{body.snmpVersion}, rocommunity = #{body.communityR},rwcommunity = #{body.communityRW},
    port_Rw = #{body.portRw}
    where id = #{netSnmpProtocol.id}
""")
} else {
    db.insert("""
    insert into ndmp_net_snmp_protocol(id,device_id, snmp_version,rocommunity,rwcommunity,port_Rw,port_trap) 
    values(#{snmpId},#{deviceId}, #{body.snmpVersion},  #{body.communityR},  #{body.communityRW},#{body.portRw},#{body.portTrap})
""")
}

var netDeviceProtocol = db.table('ndmp_net_device_protocol').where().eq("device_id", deviceId).selectOne()

var deviceProId = IdUtil.getSnowflakeNextId()
if (netDeviceProtocol != null) {
    db.update("""
   update
        ndmp_net_device_protocol
    set
        device_username = #{body.deviceUsername},
        device_password = #{body.devicePassword},
        device_id       = #{deviceId}           ,
        device_port     = #{body.devicePort}    
    where
        id = #{netDeviceProtocol.id}
""")
} else {
    db.insert("""
        insert into
          ndmp_net_device_protocol
        (
                id             ,
                device_username,
                device_password,
                device_id      ,
                device_port
        )
        values
        (
                #{deviceProId}        ,
                #{body.deviceUsername},
                #{body.devicePassword},
                #{deviceId}           ,
                #{body.devicePort}
        )


""")
}




return true